<template>
  <div>
    <van-popup v-model="couponShowPopup" position="bottom" round :close-on-click-overlay="false">
      <div class="add-info">
        <div class="coupon-list-info" v-for="(coupon, index) in coupons_new" :key="index" @click.stop="chooseCoupon(index, coupon.valid)">
          <div class="checkList" style="float: left;">
            <van-checkbox v-model="coupon.checked" shape="square" :disabled="!coupon.valid" checked-color="#f15353" :name="coupon" @change="selectCoupon_new($event, coupon)" ref="checkboxes_new">
            </van-checkbox>
            <!-- <div class="right" v-if="good_clicktag != 0">
              <van-loading />
            </div> -->
          </div>
          <div
            :class="{
              coupon_voucher_main: coupon.valid,
              coupon_voucher_gray: !coupon.valid
            }"
          >
            <div class="coupon_voucher_left">
              <div>
                <p>
                  <span v-if="coupon.discount_rule_str.is_price">¥</span>
                  {{ coupon.discount_rule_str.discount }}
                  <span v-if="coupon.discount_rule_str.is_rebate">折</span>
                </p>
                <p class="coupon_voucher_limit">{{ coupon.discount_rule_str.desc }}</p>
              </div>
            </div>
            <div class="coupon_voucher_hr"></div>
            <div class="coupon_voucher_right">
              <p class="coupon_voucher_range">
                {{ coupon.name }}
              </p>
              <!-- <p class="coupon_voucher_period">{{ coupon.time_start }}-{{ coupon.time_end }}</p> -->
            </div>
          </div>
        </div>
      </div>
      <button class="sure" type="button" @click="popupCouponSpecs_new_close">
        {{ isCueCoupon ? "确定使用" : "确认" }}
      </button>
      <button class="close" type="button" @click="popupCouponSpecs_new_close">
        {{ isCueCoupon && use_coupon_size == 0 ? "不用优惠" : "取消" }}
      </button>
    </van-popup>
  </div>
</template>
<script>
export default {
  model: {
    prop: "couponShowPopup",
    event: "onEmit"
  },
  props: ["good_clicktag", "coupons_new", "couponShowPopup"],
  data() {
    return {
      checkCouponList_new: [],
      use_coupon_size_new: 0,
    };
  },
  mounted() {},
  methods: {
    popupCouponSpecs_new_close() {
      this.$emit("close");
    },
    chooseCoupon(index, valid) {
      if (!valid) return;
      this.$refs.checkboxes_new[index].toggle();
    },
    selectCoupon_new(value, valObj) {
      let tarValue = valObj;
      console.log(valObj, value);
      if (value) {
        // 选中添加
        if (this.checkCouponList_new.length > 0) {
          for (let i = 0; i < this.checkCouponList_new.length; i++) {
            if (this.checkCouponList_new[i].id == tarValue.id) {
              this.checkCouponList_new.splice(i, 1);
            }
          }
          this.checkCouponList_new.push(tarValue);
        } else {
          this.checkCouponList_new.push(tarValue);
        }
      } else {
        // 取消选中
        if (this.checkCouponList_new.length > 0) {
          for (let i = 0; i < this.checkCouponList_new.length; i++) {
            if (this.checkCouponList_new[i].id == tarValue.id) {
              this.checkCouponList_new.splice(i, 1);
            }
          }
        }
      }
      console.log("checkCouponList_new", this.checkCouponList_new);
      this.$emit("childSelectCoupon", this.checkCouponList_new);
    }
  }
};
</script>
<style lang="scss" scoped>
.sure {
  background: #f15353;
  height: 3rem;
  line-height: 3rem;
  color: #fff;
  width: 50%;
  border: 0;
  float: left;
}

.close {
  background: #eee;
  height: 3rem;
  line-height: 3rem;
  color: #333;
  width: 50%;
  border: 0;
  float: left;
}
.add-info {
  overflow-y: scroll;
  width: 100%;
  background: #fff;
  max-height: 50vh;
  padding-top: 0.625rem;

  .coupon-list-info {
    display: flex;
    align-items: center;
    .checkList {
      margin-left: 1rem;
      flex-shrink: 0;
      .van-checkbox {
        position: relative !important;
      }
    }
    .coupon_voucher_main {
      flex: 1;
      position: relative;
      padding-left: 6.375rem;
      height: 5rem;
      margin-left: 2.25rem;
      margin-right: 0.625rem;
      margin-bottom: 0.625rem;

      .coupon_voucher_left {
        position: absolute;
        top: 0;
        left: 0;
        width: 6.375rem;
        height: 100%;
        color: #fff;
        border-radius: 0.25rem 0 0 0.25rem;
        text-align: center;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
        flex-direction: column;
        justify-content: center;
        background-color: #47c1c4;

        .coupon_voucher_amount.type_large {
          margin: 0;
          font-size: 22px;
        }

        .coupon_voucher_amount {
          position: relative;
          font-size: 36px;
          line-height: 1;
        }

        .coupon_voucher_amount::before {
          content: "\00A5";
          font-size: 16px;
          display: inline-block;
          vertical-align: text-top;
          margin-right: 0.1875rem;
          line-height: 1;
        }

        .coupon_voucher_limit {
          font-size: 12px;
          line-height: 1;
          margin-top: 0.9375rem;
          margin-bottom: 0;
        }
      }

      .coupon_voucher_hr {
        position: absolute;
        top: 0;
        left: 6.0625rem;
        width: 0.375rem;
        overflow: hidden;
        height: 100%;
      }

      .coupon_voucher_hr::after {
        box-sizing: border-box;
        position: absolute;
        top: -0.1875rem;
        right: -0.1875rem;
        bottom: 0;
        content: "• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •";
        line-height: 0.625rem;
        width: 0.4375rem;
        color: #f8fbfb;
        font-size: 18px;
        overflow: hidden;
        z-index: 1;
      }

      .coupon_voucher_right {
        box-sizing: border-box;
        padding: 0.9375rem 0.9375rem 0.9375rem 0.625rem;
        height: 100%;
        border-radius: 0 0.25rem 0.25rem 0;
        background-color: #e5f3f3;
        color: #666;
        position: relative;

        .coupon_voucher_range {
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
          font-size: 12px;
          text-align: left;
          margin: 0;
          padding: 0;
          vertical-align: baseline;
        }

        .coupon_voucher_period {
          color: #999;
          font-size: 12px;
          position: absolute;
          bottom: 0;
        }

        .coupon-stepper {
          position: absolute;
          width: 95%;
          bottom: 4px;
          right: 0.25rem;
          display: flex;
          justify-content: space-between;
          align-items: center;

          .coupon-stepper-num {
            border-radius: 0.875rem;
            overflow: hidden;
            padding: 0 0.5rem;
            color: #999;
            border: 1px solid #999;
            height: 1rem;
            font-size: 0.75rem;
            line-height: 1rem;
          }

          ::v-deep .van-stepper--round .van-stepper__minus {
            color: #47c1c4;
            border: 1px solid #47c1c4;
          }

          ::v-deep .van-stepper--round .van-stepper__plus {
            background-color: #47c1c4;
          }

          ::v-deep .maxDisabled .van-stepper__plus {
            background-color: #999;
          }
        }
      }
    }

    .coupon_voucher_gray {
      flex: 1;
      position: relative;
      padding-left: 6.375rem;
      height: 5rem;
      margin-left: 2.25rem;
      margin-right: 0.625rem;
      margin-bottom: 0.625rem;

      .coupon_voucher_left {
        position: absolute;
        top: 0;
        left: 0;
        width: 6.375rem;
        height: 100%;
        color: #fff;
        border-radius: 0.25rem 0 0 0.25rem;
        text-align: center;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
        flex-direction: column;
        justify-content: center;
        background-color: #ccc;

        .coupon_voucher_amount.type_large {
          margin: 0;
          font-size: 22px;
        }

        .coupon_voucher_amount {
          position: relative;
          font-size: 36px;
          line-height: 1;
        }

        .coupon_voucher_amount::before {
          content: "\00A5";
          font-size: 16px;
          display: inline-block;
          vertical-align: text-top;
          margin-right: 0.1875rem;
          line-height: 1;
        }

        .coupon_voucher_limit {
          font-size: 12px;
          line-height: 1;
          margin-top: 0.9375rem;
          margin-bottom: 0;
        }
      }

      .coupon_voucher_hr {
        position: absolute;
        top: 0;
        left: 6.0625rem;
        width: 0.375rem;
        overflow: hidden;
        height: 100%;
      }

      .coupon_voucher_hr::after {
        box-sizing: border-box;
        position: absolute;
        top: -0.1875rem;
        right: -0.1875rem;
        bottom: 0;
        content: "• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •";
        line-height: 0.625rem;
        width: 0.4375rem;
        color: #f8fbfb;
        font-size: 18px;
        overflow: hidden;
        z-index: 1;
      }

      .coupon_voucher_right {
        box-sizing: border-box;
        padding: 0.9375rem 0.9375rem 0.9375rem 0.625rem;
        height: 100%;
        border-radius: 0 0.25rem 0.25rem 0;
        background-color: #eee;
        color: #666;
        position: relative;

        .coupon_voucher_range {
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
          font-size: 12px;
          text-align: left;
          margin: 0;
          padding: 0;
          vertical-align: baseline;
        }

        .coupon_voucher_period {
          color: #999;
          font-size: 12px;
          position: absolute;
          bottom: 0;
        }
      }
    }
  }
}
</style>
